package com.wsx.sky.sentinel.second;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.EntryType;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.slots.block.BlockException;

/**
 * @author wangshuaixin
 * @Title: com.wsx.sky.sentinel.second.UserService
 * @Description: TODO
 * @date 2019/03/06
 */
public class UserService {



    public com.wsx.sky.sentinel.fisrt.UserService.User getUser(long uid) {
        Entry entry = null;
        try {
            //第二个参数，in为别人请求我们的限流，out是我们请求外部服务的限流
            entry = SphU.entry(com.wsx.sky.sentinel.fisrt.UserService.USER_RS, EntryType.IN);
            return new com.wsx.sky.sentinel.fisrt.UserService.User("user-" + uid, uid);
        } catch (BlockException e) {
            System.out.println("被限流了-2");
        } finally {
            if (null != entry) {
                entry.exit();
            }
        }
        return null;
    }
}
